# coding: utf8

"""
usage:
  >>> python help2doc np.array > helpdoc.txt
"""

import sys
import numpy as np
import pandas as pd
import matplotlib as mpl


def todoc(hobj, fname="help.txt"):
    """
    used to save help(hobj) to fname
    :param hobj: object name to get help doc
    :param fname: file name to save help doc
    """

    if '.' not in fname:
        fname = fname + '.txt'

    out = sys.stdout
    sys.stdout = open(fname, "w")

    if isinstance(hobj, str):
        help(eval(hobj))
    elif isinstance(hobj, object):
        help(hobj)
    else:
        # raise ValueError
        print("Fail to get doc of {}".format(hobj))

    sys.stdout.close()
    sys.stdout = out


if __name__ == '__main__':
    # usage: python help2doc np.array > helpdoc.txt
    print(help(eval(sys.argv[1])))
